<?php
/**
 * Created by PhpStorm.
 * User: ye
 * Date: 2017/11/18
 * Time: 下午5:18
 */

namespace App\Third;


use GuzzleHttp\Client;

class XcxCustom {

    public function reply($openid, $words) {
        $accessToken = new AccessToken(config('xcx.appid'), config('xcx.secret'));
        $params = [
            'touser' => $openid,
            'msgtype' => 'text',
            'text' => [
                'content' => $words
            ]
        ];
        $options = json_encode($params, JSON_UNESCAPED_UNICODE);
        $data = [
            'query' => [
                'access_token' => $accessToken->getAccessToken()
            ],
            'body' => $options,
            'headers' => ['content-type' => 'application/json']
        ];

        $client = new Client();
        $response = $client->post(config('xcx.custom_send_url'), $data);
        return json_decode($response->getBody()->getContents());
    }

}